home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Gfx / Edit / TSMorph / src / iffpstrings.c < prev    next >
C/C++ Source or Header  |  1994-10-30  |  4KB  |  185 lines

  1. /* iffpstrings.c
  2.  *
  3.  *  centralized message routine for IFFP modules
  4.  *  If you plan to add international language support to
  5.  *  your iffparse application, all of the iffparse module
  6.  *  strings are here and are accessed via the SI() macro in
  7.  *  iffp/iff.h which calls GetString() 
  8.  *
  9.  *  There is some #ifdef'd out code here which will be useful if you
  10.  *  decide to localize your application when locale.library is released.
  11.  *
  12.  *  37.9 4/92 - fixed IFFerr() error equivalence tests and null string
  13.  */
  14.  
  15. // Minor changes to errorr handling MJP
  16.  
  17. /*
  18. #define LOCALIZED
  19. */
  20.  
  21. #define INCLUDENAME    "iffp/iffpstrings.h"
  22.  
  23. #ifdef LOCALIZED
  24. #define CATALOGNAME    "yourapp.catalog"
  25. #include <clib/locale_protos.h>
  26. #ifndef NO_SAS_PRAGMAS
  27. #include <pragmas/locale_pragmas.h>
  28. #endif
  29. #endif
  30.  
  31. /* Locale stuff */
  32. #define  IFFP_MODULES
  33. #define  STRINGARRAY
  34. #include INCLUDENAME
  35.  
  36. #ifdef LOCALIZED
  37. extern struct Library *LocaleBase;
  38. #endif
  39.  
  40. extern struct AppString AppStrings[];
  41. static APTR   catalog = NULL;
  42.  
  43. /* For reference
  44. struct AppString
  45. {
  46.     LONG   as_ID;
  47.     STRPTR as_Str;
  48. };
  49. */
  50.  
  51. #include "iffp/iff.h"
  52. #include <intuition/screens.h>
  53.  
  54. static UBYTE nullstring[] = {""};
  55.  
  56. /* OpenStrings - localizes strings
  57.  * Requires open locale.library to work, but safe to call without
  58.  * You may pass nulls as args if you have no localized application strings
  59.  */
  60.  
  61. #ifdef LOCALIZED
  62. void OpenStrings()
  63.    {
  64.    if((LocaleBase)&&(!catalog))
  65.     {
  66.     catalog = OpenCatalogA(NULL,CATALOGNAME,NULL);
  67.     }
  68.     }
  69. #endif
  70.  
  71. /* CloseStrings - release the localized strings 
  72.  * Make sure all error messages are printed BEFORE calling this function
  73.  */
  74. #ifdef LOCALIZED
  75. void CloseStrings()
  76.     {
  77.     if((LocaleBase)&&(catalog))
  78.     {
  79.         CloseCatalog(catalog);
  80.     }
  81.     }
  82. #endif
  83.  
  84. /*
  85.  * IFFerr
  86.  *
  87.  * Returns pointer to IFF Error string or NULL string (no error)
  88.  */
  89. UBYTE *IFFerr(LONG error)
  90. {
  91.     /*
  92.      * English error messages for possible IFFERR_#? returns from various
  93.      * IFF routines.  To get the index into this array, take your IFFERR
  94.      * code, negate it, and subtract one.
  95.      *  idx = -error - 1;
  96.      *
  97.      * To index localized string, then add MSG_IFFP_STDFIRST
  98.      */
  99.  
  100.     static UBYTE unknown[48];
  101.     UBYTE  *s = nullstring;
  102.  
  103.     if((error < 0)&&(error >= -12))
  104.         {
  105.         s=SI(((-error) - 1) + MSG_IFFP_STDFIRST);
  106.         }
  107.     else if(error == CLIENT_ERROR)
  108.         {
  109.         s=SI(MSG_IFFP_CLIENTERR);
  110.         }
  111.     else if(error == NOFILE)
  112.         {
  113.         s=SI(MSG_IFFP_NOFILE);
  114.         }
  115.     else if(error)
  116.         {
  117. //        sprintf(unknown,SI(MSG_IFFP_UNKNOWNERR_D),error);    // MJP
  118.         s=unknown;
  119.         }
  120.     return(s);
  121. }
  122.  
  123.  
  124. /* OpenScreen error messages
  125.  */
  126. /*    MJP
  127. UBYTE *openScreenErr(ULONG errorcode)
  128.    {
  129.    static UBYTE unknown[48];
  130.    UBYTE *s=NULL;
  131.  
  132.         switch ( errorcode )
  133.     {
  134.     case OSERR_NOMEM:
  135.         s=SI(MSG_IFFP_OSNOMEM);
  136.         break;
  137.     case OSERR_NOCHIPMEM:
  138.         s=SI(MSG_IFFP_OSNOCHIPMEM);
  139.         break;
  140.     case OSERR_NOMONITOR:
  141.         s=SI(MSG_IFFP_OSNOMONITOR);
  142.         break;
  143.     case OSERR_NOCHIPS:
  144.         s=SI(MSG_IFFP_OSNOCHIPS);
  145.         break;
  146.     case OSERR_PUBNOTUNIQUE:
  147.         s=SI(MSG_IFFP_OSPUBNOTUNIQUE);
  148.         break;
  149.     case OSERR_UNKNOWNMODE:
  150.         s=SI(MSG_IFFP_OSUNKNOWNMODE);
  151.         break;
  152.     default:
  153. //        Error(SI(MSG_IFFP_OSUNKNOWNERR_D),errorcode);    // MJP
  154.         s=unknown;
  155.     }
  156.     return(s);
  157.     }
  158. */
  159.  
  160. UBYTE *XGetString(ULONG id)    // MJP (was GetString same as GadToolsBox)
  161.     {
  162.     struct AppString *as;
  163.     UBYTE *s = "";
  164.     int k,l;
  165.  
  166.     l = sizeof(AppStrings);
  167.     as = AppStrings;
  168.  
  169.     for(k=0; k<l; k++, as++)
  170.     {
  171.     if(as->as_ID == id)
  172.         {
  173.         s = as->as_Str;
  174.         break;
  175.         }
  176.     }
  177. #ifdef LOCALIZED
  178.     if((LocaleBase)&&(catalog)&&(*s))
  179.     {
  180.     s = GetCatalogStr(catalog,id,s);
  181.     }
  182. #endif
  183.     return(s);
  184.     }
  185.